package com.feihao.zhou.TCP.demoFileUpLoad;

import java.io.*;
import java.net.Socket;

public class ClientDemo {
    public static void main(String[] args) throws IOException {
        //创建socket对象：
        Socket socket = new Socket("127.0.0.1", 8088);

        OutputStream os = socket.getOutputStream();

        //读取本地文件：
        FileInputStream fis = new FileInputStream("D:\\IdeaProjects\\Job-code\\day16-code-NET\\dir\\day14-网络编程01.pdf");

        int len;
        byte[] bytes = new byte[1024];
        while ((len = fis.read(bytes)) != -1) {
            //边读边写（使用网络对象的写入流）
            os.write(bytes, 0, len);
        }
        socket.shutdownOutput();   //给服务器结束标志！！！
        //读取网络中的回写信息：
        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        String s;
        while ((s = br.readLine()) != null) {
            System.out.println(s);
        }
        //关闭资源：

        fis.close();
        br.close();
        socket.close();
    }
}
